package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.domain.SetmealDish;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @Cacheable(value = "setmeal",key = "#categoryId")
    @GetMapping(value = "/list",name = "查询所有套餐")
    public ResultInfo list(Long categoryId,Integer status){
        List<Setmeal> setmeals = setmealService.findAll(categoryId,status);
        return ResultInfo.success(setmeals);
    }

    @GetMapping(value = "/dish/{id}",name = "根据套餐id查询菜品")
    public ResultInfo dish(@PathVariable("id") Long id){
        List<SetmealDish> setmealDishes =setmealService.findBySetmealId(id);
        return ResultInfo.success(setmealDishes);
    }



}
